#include "ThreadPool.hpp"
#include "Task.hpp"
#include <string>
#include <unistd.h>

using std::string;

int main()
{
    ThreadPool<Task>* tp = ThreadPool<Task>::GetThreadPool(5);
    string OperatorSet = "+-*/%";
    tp->StartMultiThread();

    // 设置随机数种子 -- 按位异或是为了更随机一些
    srand((unsigned long)time(nullptr) ^ getpid() ^ pthread_self());
    while (true)
    {
        int Leftoperand = rand() % 40; // 取值范围：[0, 40)
        char Operator = OperatorSet[rand() % OperatorSet.size()];
        int Rightoperand = rand() % 10; // 取值范围：[0, 10)
        Task t(Leftoperand, Operator, Rightoperand);
        std::cout << Leftoperand << Operator << Rightoperand << " = " << "???" << std::endl;
        tp->PushTask(t);
        usleep(10000);
    }
    delete tp;
}